'use strict';

//云函数：获得用户账户
const db = uniCloud.database(); //打开链接
const collection = db.collection('user'); //指定表

exports.main = async (event, context) => {
	
	//event为客户端上传的参数
	if (!event.userId || !event.password) {
		return {
			code: 0,
			msg: '请检查传参！'
		};
	}
	
	let res = await collection.where({
		userId: event.userId,
		password: event.password
	}).field({
		'token': true
	}).get();
	
	//返回数据给客户端
	if (res) {
		return {
			code: 1,
			msg: '登录成功',
			data: res.data
		};
	} else {
		return {
			code: 0,
			msg: '密码或账户错误！'
		};
	}
};
